<template>
	<el-dialog title="子表权限设置" v-model="visible" :width="600" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="childrenTableRoleForm" label-width="100px" label-position="left">
			<scTable ref="table" :data="fieldsList" row-key="id" stripe>
				<el-table-column label="列名" prop="label" width="100"></el-table-column>
				<el-table-column label="字段名" prop="prop" width="100"></el-table-column>
				<el-table-column label="类型" prop="type" width="100"></el-table-column>
				<el-table-column label="权限设置">
					<template #default="scope">
						<el-radio-group v-model="childrenTableRole[scope.row.prop]">
							<el-radio-button label="0">隐藏</el-radio-button>
							<el-radio-button label="1">只读</el-radio-button>
							<el-radio-button label="2">可写</el-radio-button>
						</el-radio-group>
					</template>
				</el-table-column>
			</scTable>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="save()">确 定</el-button>
		</template>
	</el-dialog>
</template>
<script>
export default {
	emits: ['success', 'closed'],
	props: {},
	data() {
		return {
			visible: false,
			isSaveing: false,
			form: {},
			childrenTableWidget: {},
			childrenTableRole:{},
			roleInfo:{},
			fieldId:"",
			fieldsList: [],
			stepId: '',
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		save(){
			var reJson = {};
			reJson[this.fieldId] = this.childrenTableRole;
			this.$emit('success',reJson)
			this.visible = false;
		},
		onFieldsChange(val) {
			var obj = {};
			obj = this.formFieldList.find(function (item) {
				return item.id === val;
			});
			this.condition.title = obj.label;
		},
		getTableFields() {
			this.fieldId = this.childrenTableWidget.id;
			this.fieldsList = JSON.parse(this.childrenTableWidget.model);
			this.fieldsList.forEach(item=>{
				if(this.roleInfo[item.prop]!=undefined)
				{
					this.childrenTableRole[item.prop]=this.roleInfo[item.prop];
				}else
				{
					this.childrenTableRole[item.prop]="1";
				}
			})
		},
		setData(data,roleInfoStr) {
			this.childrenTableWidget = data;
			if(roleInfoStr!=null&&roleInfoStr!='')
			{
				var tempRole = JSON.parse(roleInfoStr);
				if(tempRole!=null)
				{
					this.roleInfo = tempRole[data.id]
				}
			}
			this.getTableFields();
		}

	}
}
</script>
